// Copyright 2022 Tencent
#include "util/condition.h"

namespace net_tools::util
{
  Condition::Condition(Mutex &mutex)
      : mutex_(mutex)
  {
    pthread_cond_init(&cond_, NULL);
  };
  Condition::~Condition()
  {
    pthread_cond_destroy(&cond_);
  };
  void Condition::Wait()
  {
    pthread_cond_wait(&cond_, mutex_.Get_mutex());
  };
  void Condition::Signal_one()
  {
    pthread_cond_signal(&cond_);
  };
  void Condition::Signal_all()
  {
    pthread_cond_broadcast(&cond_);
  };

} // namespace net_tools::util